const $sql = require('../utils/mysql');

module.exports = {
    getUserList() {
        let sql = "select * from t_user";
        return new Promise(resolve => {
            $sql.query(sql, (err, result) => {
                if (err) {
                    console.log('查询数据库失败', err);
                } else {
                    console.log(result);
                    let data;
                    if (result.length) {
                        data = {
                            code: 0,
                            list: result
                        }
                    } else {
                        data = {
                            code: 1,
                            msg: '没有结果 '
                        }
                    }
                    resolve(data);
                }
            })
        })
    },
    addUser(user, ws) {
        let sql = `insert into t_user values (${null},${JSON.stringify(user)},1,${JSON.stringify(ws)})`;
        return new Promise(resolve => {
            $sql.query(sql, (err, result) => {
                if (err) {
                    console.log('查询数据库失败', err);
                } else {
                    console.log(result);
                    let data;
                    if (result.length) {
                        data = {
                            code: 0,
                            list: result
                        }
                    } else {
                        data = {
                            code: 1,
                            msg: '没有结果 '
                        }
                    }
                    resolve(data);
                }
            })
        })
    }
}